<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'header.php' ?>
<div class="page-header">
	<h1 style="font-size: 20px;">
		<?php if($examId != 0): ?>
			<a class="a-back" href="<?= admin_url('contents/exam_room_data/' . $examId) ?>">
				<i class="fa fa-reply"></i>
			</a>
		<?php else: ?>
			<a class="a-back" href="<?= admin_url('contents/exam_data/') ?>">
				<i class="fa fa-reply"></i>
			</a>
		<?php endif ?>

		考试编号&nbsp;&nbsp;<?= $id ?>
		<!-- 同步学校不可添加数据 -->
		<?php if(! $rmxSchool['school_from']): ?>
			<a href="<?= admin_url('contents/save_exam_room_detail_page?room_id=' . $id) ?>" class="btn btn-info a-custom">
				<i class="ace-icon fa fa-plus"></i> 添加考场
			</a>
		<?php endif ?>
    </h1>
</div>

<div class="col-xs-12">
	<!-- 同步学校不可添加数据 -->
	<?php if(! $rmxSchool['school_from']): ?>
		<!-- <a href="<?= admin_url('contents/save_exam_room_detail_page?room_id=' . $id) ?>" class="btn btn-primary">
			<i class="ace-icon fa fa-plus"></i> 添加考场
		</a> -->
	<?php endif ?>
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
                <th>考场编号</th>
                <th>考场名称</th>
                <th>考试日期</th>
                <th>考试位置</th>
                <th>监考老师</th>
				<th>座位列表</th>
				<!-- 同步学校不可修改或删除数据 -->
				<?php if(! $rmxSchool['school_from']): ?>
					<th>操作</th>
				<?php endif ?>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	var table = "";
	$(function(){
		// 考试列表
		table = $('#dynamic-table').dt({
			"ajaxUrl": '<?= admin_url('contents/get_exam_room_detail_by_roomid?room_id=' . $id)?>',
			"columns": [
				{"data": function(ret){
	            	return ret.detail_id;
				}},
                {"data": function(ret){
	            	return ret.room_name;
				}},
                {"data": function(ret){
	            	return ret.day;
				}},				
                {"data": function(ret){
	            	return ret.location;
				}},		
                {"data": function(ret){
	            	return ret.inside_teachers;
				}},		
				{"data": function(ret){
	            	return '<a href="<?= admin_url('contents/exam_room_detail_student_data/')?>' + ret.detail_id + '" class="mr10"><i class="fa fa-gears"></i> 查看</a>';
				}},
				// 同步学校不可修改或删除数据
				<?php if(! $rmxSchool['school_from']): ?>
					{"data": function(ret){
						var action = '';
						action += '<a href="<?= admin_url('contents/save_exam_room_detail_page?room_id=' . $id . '&detail_id=') ?>' + ret.detail_id + '" class="mr10 text-success"><i class="fa fa-edit"></i> 编辑</a>&nbsp;&nbsp;';
						action += '<a data-id="'+ ret.detail_id +'" class="delete-exam-room-detail text-danger" href="javascript:;"><i class="fa fa-times"></i> 删除</a>';
						return action;
					}}
				<?php endif ?>
			]
		});
		// 删除某个考场
		$("body").on("click", ".delete-exam-room-detail", function(){
			var id = $(this).data("id");
			layer.confirm('确定删除考场编号：' + id + '吗？', function(){
				// 提交数据
				var postUrl = "<?=admin_url('contents/delete_exam_room_detail_action')?>";
				var postData = {"id": id};
				ajax_post(postUrl, postData, function(res){
					table.draw(false);
				})
			});
		})
	})
</script>